import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: '',
    username: '',
    role: '',
  }),
  getters: {
    isLoggedIn: (state) => !!state.token,
  },
  actions: {
    setUser(data) {
      console.log(data)
      this.token = data.token
      this.username = data.username
      this.role = data.role
    },
    clearUser() {
      this.token = ''
      this.username = ''
      this.role = ''
    },
  },
  persist: true, // 开启整个状态持久化，也可以是对象配置
})
